﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataBaseTable;
using System.Data;
public partial class Manage_WishNote_Mode : System.Web.UI.Page
{
    private int id=0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
        }
        if (!IsPostBack)
        {
            this.bddata();
        }
    }
    protected void bddata()
    {
        if (!IsPostBack)
        {
            this.initDropDownList();
        }
        WishingWallTable wwt = new WishingWallTable(id);
        if (wwt.ID == 0)
        {
            Response.Redirect("~/Manage/WishNote_List.aspx");
        }
        qname_tb.Text = wwt.qname;
        qtname_tb.Text = wwt.qtname;
        qqq_tb.Text = wwt.qqq;
        qdate_lb.Text = wwt.qdate.ToString();
        qip_hl.Text = wwt.qip;
        qip_hl.NavigateUrl = "http://ip.chinaz.com/?IP=" + wwt.qip;
        lei_ddl.SelectedValue = wwt.qlei;
        qgame_tb.Text = wwt.qgame;
        if (wwt.qshenhe == 1)
        {
            qshenhe_cb.Checked = true;
        }
        else
        {
            qshenhe_cb.Checked = false ;
        }

    }
    private void initDropDownList()
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(@"~/XML/BlessingType.xml"));
        lei_ddl.DataSource = ds;
        lei_ddl.DataTextField = "value";
        lei_ddl.DataValueField = "id";
        lei_ddl.DataBind();
    }
    protected void submit_btn_Click(object sender, EventArgs e)
    {
        WishingWallTable wwt = new WishingWallTable(id);
        wwt.qname = qname_tb.Text;
        wwt.qtname=qtname_tb.Text ;
        wwt.qqq=qqq_tb.Text ;
        wwt.qlei=lei_ddl.SelectedValue;
        wwt.qgame=qgame_tb.Text;
        if (qshenhe_cb.Checked )
        {
            wwt.qshenhe = 1;
        }
        else
        {
            wwt.qshenhe = 0;
        }
        try
        {
            wwt.Update();
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('更新成功');</script>");
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('更新失败');</script>");
        }
    }
}